Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/database/src/commonMain/kotlin/org/meshtastic/core/database/DatabaseProvider.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 2.53 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.database

Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow

T8b949e/**
* Provides multiplatform access to the current [MeshtasticDatabase] and a safe transactional helper. Platform
* implementations manage the concrete lifecycle (Room on Android, etc.).
*
* **Write policy:** every one-shot DAO *write* (insert/upsert/update/delete/clear) must go through [withDb], never
* `currentDb.value` directly. [withDb] registers the write with the cross-transport merge drain barrier (see
* [DatabaseManager.associateDevice]) so a merge can't snapshot a database while the write is still in flight and lose
* it when that database is retired. The callback is never replayed automatically after it starts: callers that need
* retries must make that policy explicit at a higher layer where idempotency is known.
*
* One-shot DAO *reads* use [withReadDb]. They stay out of writer admission and the serialized containment lane; the
* logical-retirement guarantee in [DatabaseManager] keeps a captured published pool alive for the process lifetime.
* [currentDb] itself remains the right latch for Flow/Paging factories, which must re-latch on database switches.
*/
Tff7b72interface T56d364DatabaseProvider Tb4b4b4{
T8b949e/** Reactive stream of the currently active database instance. */
Tff7b72val Te6edf3currentDbTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3MeshtasticDatabaseTff7b72>

T8b949e/**
* Execute one bounded read against the synchronously published current database without writer admission. The read
* is tracked through orderly shutdown and fails with [IllegalStateException] if admission starts after shutdown.
*/
Tff7b72suspend Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffwithReadDbTb4b4b4(Te6edf3blockTb4b4b4: Te6edf3suspend Tb4b4b4(Te6edf3MeshtasticDatabaseTb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4)Tb4b4b4: Te6edf3T

T8b949e/** Execute [block] against the current database, returning `null` if no database is available. */
Tff7b72suspend Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffwithDbTb4b4b4(Te6edf3blockTb4b4b4: Te6edf3suspend Tb4b4b4(Te6edf3MeshtasticDatabaseTb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4)Tb4b4b4: Te6edf3T?
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s